import request, { METHOD } from '@/service/request.service';
import { formatTableResult, defaultPagination } from './common';

export function getGood(id){
  uni.showLoading();
  return request({
    url: `/good`,
    method: METHOD.GET,
    params: {
      id
    },
  }).then((response)=> {
    uni.hideLoading();
    return response
  }).catch((error) => {
    uni.hideLoading();
    return error
  })
}
export function getGoodList(params){
  return request({
    url: '/goods',
    method: METHOD.GET,
    params: {
    	...defaultPagination,
    	...params
    },
  }).then(formatTableResult)
}

export function createGood(data){
  uni.showLoading();
  
  return request({
    url: '/good',
    method: METHOD.POST,
    data
  }).then((response)=> {
    uni.hideLoading();
    uni.showToast({
      title: '创建成功',
      duration: 1000
    });
    return response
  }).catch((error) => {
    uni.hideLoading();
    return error
  })
}

export function modifyGood(id){
  return request({
    url: `/good`,
    method: METHOD.PUT,
  })
}



export function getCollectGoodList(params){
  return request({
    url: `/goods/collect`,
    method: METHOD.GET,
    params: {
    	...defaultPagination,
    	...params
    },
  }).then(formatTableResult)
}


export function getUserGoodList(params){
  return request({
    url: `/goods/user`,
    method: METHOD.GET,
    params: {
    	...defaultPagination,
    	...params
    },
  }).then(formatTableResult)
}

